package com.lz.sports.service

import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.IBinder
import com.lz.comm.extension.toJsonRequestBody
import com.lz.comm.extension.toTextRequestBody
import com.lz.comm.extension.toZipPart
import com.lz.comm.net.HttpManager
import com.lz.library.extension.timer
import com.lz.library.net.NetworkManager
import com.lz.sports.LogUtils
import com.lz.sports.api.UploadApi
import com.lz.sports.db.ExamineeDatabase
import com.lz.sports.utils.ImportsUtils
import com.lz.sports.utils.UploadUtils
import com.lz.sports.utils.toGson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import java.io.File


//定时上传
class UploadService : Service() {

    companion object {
        //网络状态请求
        private const val NETWORK_DELAY = 30000L

        //上传延时时间
        private const val UPLOAD_DELAY = 20000L

        fun start(context: Context) {
            context.startService(Intent(context, UploadService::class.java))
        }
    }

    private var uploadApi: UploadApi? = null

    private val scope by lazy { MainScope() }

    //是否正在上传信息
    private var isUploadLoadingInfo = false

    //是否正在上传压缩包
    private var isUploadLoadingZip = false


    override fun onBind(intent: Intent?): IBinder? = null

    override fun onCreate() {
        super.onCreate()

        scope.launch {
            timer(NETWORK_DELAY).collect {
                networkCheck()
            }
        }
        scope.launch {
            timer(UPLOAD_DELAY).collect {
                if (NetworkManager.isNetworkConnected() && ServiceStatusManager.isNetwork) {
                    uploadInfo()
                    uploadZip()
                }
            }
        }
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        uploadApi = HttpManager.getService(UploadApi::class.java)
        return super.onStartCommand(intent, flags, startId)
    }

    private var isNetworkCheck = false
    private fun networkCheck() {
        if (isNetworkCheck) return
        val api = uploadApi ?: return
        scope.launch {
            api.lineStatus()
                .catch { isNetworkCheck = false; ServiceStatusManager.changeStatus(false) }
                .onStart { isNetworkCheck = true }
                .onCompletion { isNetworkCheck = false }
                .collect {
                    if (it.isSuccess()) {
                        ServiceStatusManager.changeStatus(true)
                    } else {
                        ServiceStatusManager.changeStatus(false)
                    }
                }
        }

    }

    private fun uploadInfo() {
        if (isUploadLoadingInfo) return
        val api = uploadApi ?: return
        scope.launch {
            flow {
                emit(uploadSignIn(api))
                emit(uploadInspect(api))
                emit(uploadExamList(api))
                emit(uploadSureList(api))
                emit(uploadResultList(api))
                emit(uploadLackList(api))
            }.flowOn(Dispatchers.IO).catch {
                isUploadLoadingInfo = false
                LogUtils.i("uploadInfo exception...")
            }.onStart {
                isUploadLoadingInfo = true
                LogUtils.i("uploadInfo start...")
            }.onCompletion {
                isUploadLoadingInfo = false
                LogUtils.i("uploadInfo onCompletion...")
            }.collect {
                LogUtils.i("uploadInfo result = $it")
            }
        }
    }

    private fun uploadZip() {
        if (isUploadLoadingZip) return
        val api = uploadApi ?: return
        scope.launch {
            flow {
                emit(uploadInspectIdCardPhotoList(api))
                emit(uploadInspectScenePhotoList(api))
                emit(uploadInspectExamPhotoList(api))

                emit(uploadSignIdCardPhotoList(api))
                emit(uploadSignScenePhotoList(api))
                emit(uploadSignExamPhotoList(api))

                emit(uploadSureIdCardPhotoList(api))
                emit(uploadSureScenePhotoList(api))
                emit(uploadSureExamPhotoList(api))
                emit(uploadSureSignaturePhotoList(api))
            }.flowOn(Dispatchers.IO).catch {
                isUploadLoadingZip = false
                LogUtils.i("uploadZip catch exception...")
            }.onStart {
                isUploadLoadingZip = true
                LogUtils.i("uploadZip is start...")
            }.onCompletion {
                isUploadLoadingZip = false
                LogUtils.i("uploadZip is onCompletion...")
            }.collect {
                LogUtils.i("uploadZip result = $it")
            }
        }
    }

    //上传签到信息
    private fun uploadSignIn(api: UploadApi): Boolean {
        try {
            val signList = ExamineeDatabase.get().signUploadList()
            if (signList.isNotEmpty()) {
                val gson = "{\"busExamStuRegisterList\":${signList.toGson()}}"
                LogUtils.i("uploadSignIn ListJson = $gson")
                val res = api.signIn(gson.toJsonRequestBody()).execute().body()
                if (res != null && res.success()) {
                    LogUtils.i("uploadSignIn success ")
                    signList.forEach { signIn -> signIn.uploadStatus = 0 }
                    ExamineeDatabase.get().updateExamSignList(signList) //更新上传状态
                    return true
                }
            } else {
                LogUtils.i("uploadSignIn list isEmpty")
            }
        } catch (_: Exception) {
        }
        return false
    }

    //上传检录信息
    private fun uploadInspect(api: UploadApi): Boolean {
        try {
            val inspectList = ExamineeDatabase.get().inspectUploadList()
            if (inspectList.isNotEmpty()) {
                val gson = "{\"busExamStuRegisterCheckList\":${inspectList.toGson()}}"
                LogUtils.i("uploadInspect ListJson = $gson")
                val res = api.inspect(gson.toJsonRequestBody()).execute().body()
                if (res != null && res.success()) {
                    LogUtils.i("uploadInspect success ")
                    inspectList.forEach { inspect -> inspect.uploadStatus = 0 }
                    ExamineeDatabase.get().updateExamInspectList(inspectList) //更新上传状态
                    return true
                }
            } else {
                LogUtils.i("uploadSignIn list isEmpty")
            }
        } catch (_: Exception) {
        }
        return false
    }

    //上传考试信息
    private fun uploadExamList(api: UploadApi): Boolean {
        try {
            val examInspectList = ExamineeDatabase.get().examUploadList()
            if (examInspectList.isNotEmpty()) {
                val gson = "{\"busExamStuHistoryGradeList\":${examInspectList.toGson()}}"
                LogUtils.i("uploadExam ListJson = $gson")
                val res = api.examinee(gson.toJsonRequestBody()).execute().body()
                if (res != null && res.success()) {
                    LogUtils.i("uploadExamList success ")
                    examInspectList.forEach { inspect -> inspect.examUploadStatus = 0 }
                    ExamineeDatabase.get().updateExamInspectList(examInspectList) //更新上传状态
                    return true
                }
            } else {
                LogUtils.i("uploadExamList list isEmpty")
            }
        } catch (_: Exception) {
        }
        return false
    }

    //上传最终成绩
    private fun uploadResultList(api: UploadApi): Boolean {
        try {
            val resultList = ExamineeDatabase.get().resultUploadList()
            if (resultList.isNotEmpty()) {
                val gson = "{\"busExamStuFinalGradeList\":${resultList.toGson()}}"
                LogUtils.i("uploadResult ListJson = $gson")
                val res = api.result(gson.toJsonRequestBody()).execute().body()
                if (res != null && res.success()) {
                    LogUtils.i("uploadResultList success ")
                    resultList.forEach { result -> result.uploadStatus = 0 }
                    ExamineeDatabase.get().updateExamResultList(resultList) //更新上传状态
                    return true
                }
            } else {
                LogUtils.i("uploadResultList list isEmpty")
            }
        } catch (_: Exception) {
        }
        return false
    }

    //上传成绩确认
    private fun uploadSureList(api: UploadApi): Boolean {
        try {
            val resultList = ExamineeDatabase.get().sureUploadList()
            if (resultList.isNotEmpty()) {
                val gson = "{\"busExamStuConfirmGradeList\":${resultList.toGson()}}"
                LogUtils.i("uploadSure ListJson = $gson")
                val res = api.sure(gson.toJsonRequestBody()).execute().body()
                if (res != null && res.success()) {
                    LogUtils.i("uploadSureList success ")
                    resultList.forEach { result -> result.uploadStatus = 0 }
                    ExamineeDatabase.get().updateExamSureList(resultList) //更新上传状态
                    return true
                }
            } else {
                LogUtils.i("uploadSureList list isEmpty")
            }
        } catch (_: Exception) {
        }
        return false
    }

    //上传缺考
    private fun uploadLackList(api: UploadApi): Boolean {
        try {
            val resultList = ExamineeDatabase.get().lackUploadList()
            if (resultList.isNotEmpty()) {
                val gson = "{\"busExamStuMissList\":${resultList.toGson()}}"
                LogUtils.i("uploadLackList ListJson = $gson")
                val res = api.lack(gson.toJsonRequestBody()).execute().body()
                if (res != null && res.success()) {
                    LogUtils.i("uploadLackList success ")
                    resultList.forEach { result -> result.lackUploadStatus = 0 }
                    ExamineeDatabase.get().updateExamResultList(resultList) //更新上传状态
                    return true
                }
            } else {
                LogUtils.i("uploadLackList list isEmpty")
            }
        } catch (_: Exception) {
        }
        return false
    }

    //上传检录组的身份证照片
    private fun uploadInspectIdCardPhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().inspectIdCardPhotoUploadList()
            LogUtils.i("inspectUploadIdCardPhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val inspectPhotoFile = it.idCardImgFile()
                if (inspectPhotoFile.exists() && inspectPhotoFile.isFile) {
                    fileList.add(inspectPhotoFile)
                    LogUtils.i("uploadInspectIdCardPhotoList = ${inspectPhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadInspectIdCardPhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examInspectPath(), "InspectIdCard_$time.zip")
            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadInspectIdCardPhotoList zip res = $zipRes ")
            val res = api.uploads(zipFile.toZipPart("file"), "REGISTER_CHECK_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { inspect -> inspect.idCardPhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamInspectList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传检录组的现场照片
    private fun uploadInspectScenePhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().inspectScenePhotoUploadList()
            LogUtils.i("uploadInspectScenePhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val inspectPhotoFile = it.sceneImgFile()
                if (inspectPhotoFile.exists() && inspectPhotoFile.isFile) {
                    fileList.add(inspectPhotoFile)
                    LogUtils.i("uploadInspectScenePhotoList = ${inspectPhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadInspectScenePhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examInspectPath(), "InspectScene_$time.zip")
            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadInspectScenePhotoList zip res = $zipRes ")
            val res = api.uploads(zipFile.toZipPart("file"), "REGISTER_CHECK_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { inspect -> inspect.scenePhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamInspectList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传检录组的报名照片
    private fun uploadInspectExamPhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().inspectExamPhotoUploadList()
            LogUtils.i("uploadInspectExamPhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val inspectPhotoFile = it.examImgFile()
                if (inspectPhotoFile.exists() && inspectPhotoFile.isFile) {
                    fileList.add(inspectPhotoFile)
                    LogUtils.i("uploadInspectExamPhotoList = ${inspectPhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadInspectExamPhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examInspectPath(), "InspectExam_$time.zip")
            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadInspectExamPhotoList zip res = $zipRes")
            val res = api.uploads(zipFile.toZipPart("file"), "REGISTER_CHECK_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { inspect -> inspect.examPhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamInspectList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传签到组的身份证照片
    private fun uploadSignIdCardPhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().signIdCardPhotoUploadList()
            LogUtils.i("uploadSignIdCardPhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val inspectPhotoFile = it.idCardImgFile()
                if (inspectPhotoFile.exists() && inspectPhotoFile.isFile) {
                    fileList.add(inspectPhotoFile)
                    LogUtils.i("uploadSignIdCardPhotoList = ${inspectPhotoFile.absolutePath}")
                }
            }
            LogUtils.i("idCard fileList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examSignInPath(), "SignInIdCard_$time.zip")


            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadSignIdCardPhotoList zip res = $zipRes ")
            val res = api.uploads(zipFile.toZipPart("file"), "REGISTER_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { signIn -> signIn.idCardPhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamSignList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传签到组的现场照片
    private fun uploadSignScenePhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().signScenePhotoUploadList()
            LogUtils.i("uploadSignScenePhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val inspectPhotoFile = it.sceneImgFile()
                if (inspectPhotoFile.exists() && inspectPhotoFile.isFile) {
                    fileList.add(inspectPhotoFile)
                    LogUtils.i("uploadSignScenePhotoList = ${inspectPhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadSignScenePhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examSignInPath(), "SignInScene_$time.zip")


            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadSignScenePhotoList zip res = $zipRes ")
            val res = api.uploads(zipFile.toZipPart("file"), "REGISTER_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { signIn -> signIn.scenePhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamSignList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传签到组的报名照片
    private fun uploadSignExamPhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().signExamPhotoUploadList()
            LogUtils.i("uploadSignExamPhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val inspectPhotoFile = it.examImgFile()
                if (inspectPhotoFile.exists() && inspectPhotoFile.isFile) {
                    fileList.add(inspectPhotoFile)
                    LogUtils.i("uploadSignExamPhotoList = ${inspectPhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadSignExamPhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examSignInPath(), "SignExam_$time.zip")

            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadSignExamPhotoList zip res = $zipRes ")
            val res = api.uploads(zipFile.toZipPart("file"), "REGISTER_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { signIn -> signIn.examPhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamSignList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传成绩确认身份证照片
    private fun uploadSureIdCardPhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().sureIdCardPhotoUploadList()
            LogUtils.i("uploadSureIdCardPhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val surePhotoFile = it.idCardImgFile()
                if (surePhotoFile.exists() && surePhotoFile.isFile) {
                    fileList.add(surePhotoFile)
                    LogUtils.i("uploadSureIdCardPhotoList = ${surePhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadSureIdCardPhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examSurePath(), "SureIdCard_$time.zip")

            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadSureIdCardPhotoList zip res = $zipRes")
            val res = api.uploads(zipFile.toZipPart("file"), "CONFIRM_GRADE_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { sure -> sure.idCardPhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamSureList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传成绩确认现场照
    private fun uploadSureScenePhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().sureScenePhotoUploadList()
            LogUtils.i("uploadSureScenePhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val surePhotoFile = it.sceneImgFile()
                if (surePhotoFile.exists() && surePhotoFile.isFile) {
                    fileList.add(surePhotoFile)
                    LogUtils.i("uploadSureScenePhotoList = ${surePhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadSureScenePhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examSurePath(), "SureScene_$time.zip")

            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadSureScenePhotoList zip res = $zipRes ")
            val res = api.uploads(zipFile.toZipPart("file"), "CONFIRM_GRADE_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { sure -> sure.scenePhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamSureList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传成绩确认报名照
    private fun uploadSureExamPhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().sureExamPhotoUploadList()
            LogUtils.i("uploadSureExamPhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val surePhotoFile = it.examImgFile()
                if (surePhotoFile.exists() && surePhotoFile.isFile) {
                    fileList.add(surePhotoFile)
                    LogUtils.i("uploadSureExamPhotoList = ${surePhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadSureExamPhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examSurePath(), "SureExam_$time.zip")

            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadSureExamPhotoList zip res = $zipRes ")
            val res = api.uploads(zipFile.toZipPart("file"), "CONFIRM_GRADE_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { sure -> sure.examPhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamSureList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    //上传成绩确认电子签名照
    private fun uploadSureSignaturePhotoList(api: UploadApi): Boolean {
        var zipFile: File? = null
        try {
            val uploadList = ExamineeDatabase.get().sureSignaturePhotoUploadList()
            LogUtils.i("uploadSureSignaturePhotoList $uploadList")
            if (uploadList.isEmpty()) return false
            val fileList = ArrayList<File>()
            uploadList.forEach {
                val surePhotoFile = it.signatureImgFile()
                if (surePhotoFile.exists() && surePhotoFile.isFile) {
                    fileList.add(surePhotoFile)
                    LogUtils.i("uploadSureSignaturePhotoList = ${surePhotoFile.absolutePath}")
                }
            }
            LogUtils.i("uploadSureSignaturePhotoList = ${fileList.size}")
            if (fileList.isEmpty()) return false
            val time = System.currentTimeMillis()
            zipFile = File(UploadUtils.examSurePath(), "SureSignature_$time.zip")

            val zipRes = ImportsUtils.zipFile(fileList, zipFile, "$time")
            LogUtils.i("uploadSureSignaturePhotoList zip res = $zipRes ")
            val res = api.uploads(zipFile.toZipPart("file"), "CONFIRM_GRADE_IMAGES".toTextRequestBody())
                .execute().body()
            if (res != null && res.success()) {
                uploadList.forEach { sure -> sure.signaturePhotoUploadStatus = 0 }
                ExamineeDatabase.get().updateExamSureList(uploadList) //更新上传状态
                return true
            }
        } catch (_: Exception) {
        } finally {
            zipFile?.delete()
        }
        return false
    }

    override fun onDestroy() {
        super.onDestroy()
        scope.cancel()
    }
}